package main

import (
	"github.com/gin-gonic/gin"
	"hanlinyuan_qa/ip"
	"hanlinyuan_qa/model"
	"hanlinyuan_qa/service"
	"hanlinyuan_qa/util"
	"log"
)

func main() {
	model.CreateTable()
	ip.InitIpLocation()
	router := gin.Default()
	router.Use(util.JWTAuthMiddleware())
	router.GET("/test", service.Test)
	router.POST("/api/login", service.Login)
	router.POST("/api/create_qa", service.CreateQuestion)
	router.POST("/api/update_qa", service.UpdateQuestion)
	router.POST("/api/answer", service.UploadAnswer)
	router.POST("/api/get_q", service.GetQuestion)
	router.POST("/api/admin/get_q", service.AdminGetQuestion)
	router.POST("/api/admin/get_deleted", service.GetDeletedQuestion)
	router.POST("/api/admin/delete_qa", service.DeleteQuestion)
	router.POST("/api/admin/recover_qa", service.RecoverQuestion)
	router.POST("/api/admin/get_q_total", service.AdminGetQuestionTotal)
	router.POST("/api/admin/get_a_detail", service.GetAnswerDetail)
	router.POST("/api/admin/share", service.GetShareData)
	// 启动HTTP服务器
	err := router.Run(":8091")
	if err != nil {
		log.Fatal("启动服务器失败:", err)
	}
}
